//TOWN SCRIPT TEMPLATE

begintownscript;

variables;
short choice;
string dlgstr;

body;

beginstate INIT_STATE;
	set_crime_tolerance(1);
break;

beginstate EXIT_STATE;
//called when the party leaves the town
	text_bubble_on_char(0,"");
	text_bubble_on_char(1,"");
	text_bubble_on_char(2,"");
	text_bubble_on_char(3,"");

break;

beginstate START_STATE;
//called every turn when the party is in the town
	set_name(6,"Machrone");
	set_name(7,"Innkeeper");
	set_name(15,"Mysterious Wizard");
break;

beginstate 10;
if (get_flag(3,1)) {
	reset_dialog();
	add_dialog_str(0,"You return to your quarters. What do you wish to do?",0);
	add_dialog_choice(0,"Leave.");
	add_dialog_choice(1,"Go back to sleep.");
	if (run_dialog(1) == 1)
		block_entry(1);
	else {
		message_dialog("The party splits again, and you go back to sleep. The rest of the night passes dreamlessly.","You wake the following morning, ready to face the new day!");
		set_ticks_forward (5000 - (get_current_tick() % 5000));
		move_to_new_town(0,7,9);
		}
	}
break;

beginstate 11;
if (get_flag(3,1)) {
	message_dialog("You've already said what you need to say to Machrone. You leave him be for the moment.","");
	end();
	}

	message_dialog("You approach this old man to speak to him. He looks at you anxiously as you approach. _Ah, it's you,_ he says. _I was waiting for you._","You recognize him from the common room. This is Machrone. He has a nasty gash across his cheek that he didn't have in the common room, though, and you notice a few other small wounds, too. The fight that just happened must have involved him.");

	text_bubble_on_char(0,"Why were you waiting for us?");
	force_instant_terrain_redraw();
	pause(5 * get_flag(290,0));

	text_bubble_on_char(0,"");
	text_bubble_on_char(6,"I knew that someone would come");
	force_instant_terrain_redraw();
	pause(5 * get_flag(290,0));

	text_bubble_on_char(6,"");
	text_bubble_on_char(6,"after hearing that scuffle");
	force_instant_terrain_redraw();
	pause(5 * get_flag(290,0));

	text_bubble_on_char(6,"");
	text_bubble_on_char(6,"and I guessed it'd be you.");
	force_instant_terrain_redraw();
	pause(5 * get_flag(290,0));

	text_bubble_on_char(6,"");
	text_bubble_on_char(6,"I know you've been looking");
	force_instant_terrain_redraw();
	pause(5 * get_flag(290,0));

	text_bubble_on_char(6,"");
	text_bubble_on_char(6,"for your first quest.");
	force_instant_terrain_redraw();
	pause(5 * get_flag(290,0));

	text_bubble_on_char(6,"");
	force_instant_terrain_redraw();

	message_dialog("You start to protest.","");

	text_bubble_on_char(0,"First?");
	force_instant_terrain_redraw();
	pause(5 * get_flag(290,0));

	text_bubble_on_char(0,"");
	text_bubble_on_char(0,"We are EXPERIENCED adventurers!");
	force_instant_terrain_redraw();
	pause(5 * get_flag(290,0));

	text_bubble_on_char(0,"");
	text_bubble_on_char(0,"We defeated the great, um,");
	force_instant_terrain_redraw();
	pause(5 * get_flag(290,0));

	text_bubble_on_char(0,"");
	text_bubble_on_char(0,"Fire-Breathing Weasel of Gale!");
	force_instant_terrain_redraw();
	pause(5 * get_flag(290,0));

	text_bubble_on_char(0,"");
	force_instant_terrain_redraw();
	pause(5 * get_flag(290,0));

	text_bubble_on_char(0,"Really.");
	force_instant_terrain_redraw();
	pause(5 * get_flag(290,0));

	text_bubble_on_char(0,"");
	text_bubble_on_char(0,"I swear.");
	force_instant_terrain_redraw();
	pause(5 * get_flag(290,0));

	text_bubble_on_char(0,"");
	force_instant_terrain_redraw();

	message_dialog("Machrone's eyebrows nearly disappear into his white hair.","");

	text_bubble_on_char(6,"Suuuure you did.");
	force_instant_terrain_redraw();
	pause(5 * get_flag(290,0));

	text_bubble_on_char(6,"");
	text_bubble_on_char(6,"But I am prepared to offer you");
	force_instant_terrain_redraw();
	pause(5 * get_flag(290,0));

	text_bubble_on_char(6,"");
	text_bubble_on_char(6,"a chance at great renown!");
	force_instant_terrain_redraw();
	pause(5 * get_flag(290,0));

	text_bubble_on_char(6,"");
	text_bubble_on_char(6,"Fortune and glory!!");
	force_instant_terrain_redraw();
	pause(5 * get_flag(290,0));

	text_bubble_on_char(6,"");
	text_bubble_on_char(6,"Or something.");
	force_instant_terrain_redraw();
	pause(5 * get_flag(290,0));

	text_bubble_on_char(6,"");
	force_instant_terrain_redraw();

	message_dialog("You are about to beg him to tell you more, to give you the opportunity that you've been seeking for as long as you can remember, to volunteer for whatever task he will give you. But before you can speak....","");

	text_bubble_on_char(3,"Wait, what do you mean,");
	force_instant_terrain_redraw();
	pause(5 * get_flag(290,0));

	text_bubble_on_char(3,"");
	text_bubble_on_char(3,"'Or something'?");
	force_instant_terrain_redraw();
	pause(5 * get_flag(290,0));

	text_bubble_on_char(3,"");
	text_bubble_on_char(6,"What?");
	force_instant_terrain_redraw();
	pause(5 * get_flag(290,0));

	text_bubble_on_char(6,"");
	text_bubble_on_char(3,"That's what you said.");
	force_instant_terrain_redraw();
	pause(5 * get_flag(290,0));

	text_bubble_on_char(3,"");
	text_bubble_on_char(3,"'Fortune and glory. Or something.'");
	force_instant_terrain_redraw();
	pause(5 * get_flag(290,0));

	text_bubble_on_char(3,"");
	text_bubble_on_char(3,"You wouldn't have said that");
	force_instant_terrain_redraw();
	pause(5 * get_flag(290,0));

	text_bubble_on_char(3,"");
	text_bubble_on_char(3,"unless you had doubts about our quest.");
	force_instant_terrain_redraw();
	pause(5 * get_flag(290,0));

	text_bubble_on_char(3,"");
	clear_buffer();
	append_char_name(3);
	append_string(",");
	get_buffer_text(dlgstr);
	text_bubble_on_char(0,dlgstr);
	force_instant_terrain_redraw();
	pause(5 * get_flag(290,0));

	text_bubble_on_char(0,"");
	text_bubble_on_char(0,"ix-nay on the umb-day estions-quay!");
	force_instant_terrain_redraw();
	pause(6 * get_flag(290,0));

	text_bubble_on_char(0,"");
	text_bubble_on_char(6,"I don't understand.");
	force_instant_terrain_redraw();
	pause(5 * get_flag(290,0));

	text_bubble_on_char(6,"");
	text_bubble_on_char(0,"Never mind. You were saying?");
	force_instant_terrain_redraw();
	pause(5 * get_flag(290,0));

	text_bubble_on_char(0,"");
	force_instant_terrain_redraw();

	reset_dialog();
	add_dialog_str(0,"_Yes,_ Machrone replies, continuing. _I've been robbed!_ He shakes his head in sadness. ",0);
	add_dialog_str(1,"_A box, worthless but for the priceless artifact that it contains, has been stolen right out of my room. I tried to stop it from happening, but I was overpowered._ He shakes his right hand in pain. It is bleeding.",0);
	add_dialog_str(2,"_They surely cannot get it open, so its contents are unimportant. I need you to fetch me the box, whole and intact, before they get frustrated and destroy it._",0);
	run_dialog(1);

	text_bubble_on_char(0,"They?");
	force_instant_terrain_redraw();
	pause(5 * get_flag(290,0));

	text_bubble_on_char(0,"");
	text_bubble_on_char(0,"Who took it?");
	force_instant_terrain_redraw();
	pause(5 * get_flag(290,0));

	text_bubble_on_char(0,"");
	text_bubble_on_char(6,"Goblins. I'm sure of it.");
	force_instant_terrain_redraw();
	pause(5 * get_flag(290,0));

	text_bubble_on_char(6,"");
	force_instant_terrain_redraw();
	
	message_dialog("_It was goblins, I'm sure,_ he says. _It was dark, so I didn't see them clearly, but it must have been at least four or five goblins._","");
	
	text_bubble_on_char(3,"Goblins!");
	force_instant_terrain_redraw();
	pause(5 * get_flag(290,0));

	text_bubble_on_char(3,"");
	text_bubble_on_char(3,"Why does it always have to be goblins?");
	force_instant_terrain_redraw();
	pause(5 * get_flag(290,0));

	text_bubble_on_char(3,"");
	text_bubble_on_char(2,"I'm SCARED of goblins!!");
	force_instant_terrain_redraw();
	pause(5 * get_flag(290,0));

	text_bubble_on_char(2,"");
	text_bubble_on_char(3,"That's why you're still level 1.");
	force_instant_terrain_redraw();
	pause(5 * get_flag(290,0));

	text_bubble_on_char(3,"");
	text_bubble_on_char(3,"*snicker*");
	force_instant_terrain_redraw();
	pause(5 * get_flag(290,0));

	text_bubble_on_char(3,"");
	text_bubble_on_char(2,"Hey!!");
	force_instant_terrain_redraw();
	pause(5 * get_flag(290,0));

	text_bubble_on_char(2,"");
	text_bubble_on_char(0,"Shut up!");
	force_instant_terrain_redraw();
	pause(5 * get_flag(290,0));

	text_bubble_on_char(0,"");
	text_bubble_on_char(0,"All of you, shut up!");
	force_instant_terrain_redraw();
	pause(5 * get_flag(290,0));

	text_bubble_on_char(0,"");
	text_bubble_on_char(0,"Go on, Machrone.");
	force_instant_terrain_redraw();
	pause(5 * get_flag(290,0));

	text_bubble_on_char(0,"");
	force_instant_terrain_redraw();
	
	reset_dialog();
	add_dialog_str(0,"_I need the four of you to retrieve my box from the goblins. They have a cave just north of here. The box is small and gold-colored, and it has the emblem of a quill on it._",0);
	add_dialog_str(1,"He adds, _I'll reward you handsomely. I'll pay a thousand -- I mean, what level did you say that you were again?_",0);
	add_dialog_str(2,"You start to bluster again that you're very experienced adventurers, but he waves his hand and scans you magically. _Level one,_ he mutters to himself. _Hmm. Can't be worth more than a hundred coins._",0);
	add_dialog_str(3,"_I'll pay you a hundred coins if you return my box to me,_ he concludes.",0);
	add_dialog_choice(0,"Okay, we'll do it.");
	add_dialog_choice(1,"A hundred coins? What was that about a thousand a second ago?");
	add_dialog_choice(2,"Sorry, old man, not interested.");
	choice = run_dialog(1);

	if (choice == 1)
		set_flag(3,1,1);
	if (choice == 2) {
		text_bubble_on_char(6,"You drive a hard bargain.");
		force_instant_terrain_redraw();
		pause(5 * get_flag(290,0));

		text_bubble_on_char(6,"");
		text_bubble_on_char(0,"We'll do it for five hundred.");
		force_instant_terrain_redraw();
		pause(5 * get_flag(290,0));

		text_bubble_on_char(0,"");
		text_bubble_on_char(6,"Two hundred.");
		force_instant_terrain_redraw();
		pause(5 * get_flag(290,0));

		text_bubble_on_char(6,"");
		text_bubble_on_char(0,"Four hundred, and not a coin less.");
		force_instant_terrain_redraw();
		pause(5 * get_flag(290,0));

		text_bubble_on_char(0,"");
		text_bubble_on_char(6,"Three hundred. Final offer.");
		force_instant_terrain_redraw();
		pause(5 * get_flag(290,0));

		text_bubble_on_char(6,"");
		text_bubble_on_char(0,"Done!");
		force_instant_terrain_redraw();
		pause(5 * get_flag(290,0));
		
		set_flag(3,1,3);
		}
	if (choice == 3) {
		reset_dialog();
		add_dialog_str(0,"_Are you sure?_ Machrone asks. _I need help! Please, save my box!_",0);
		add_dialog_choice(0,"I changed my mind. We'll do it.");
		add_dialog_choice(1,"Yes, I'm sure. Let's get the heck out of here.");
		if (run_dialog(1) == 1)
			set_flag(3,1,1);
		else {
			set_flag(3,1,5);
			message_dialog("_Well, I cannot force you,_ Machrone says, disappointed. _But I will remember this, and you will not find anything of use or value in this part of the mountains._ He sighs and falls silent.","");
			end();
			}
		}

	text_bubble_on_char(0,"");
	text_bubble_on_char(1,"");
	text_bubble_on_char(2,"");
	text_bubble_on_char(3,"");
	force_instant_terrain_redraw();

	message_dialog("_Good,_ Machrone says. _It would be foolish to try to attack the goblins in the middle of the night, so you should wait until morning to go after them. Sleep now. But remember, bring me my box and you will be rewarded. Fame! Wealth! Or something._","He adds, _Good night, adventurers._");

	toggle_quest(0,1);
	
break;

beginstate 12;
	message_dialog("This door is locked firmly from the other side. For whatever reason, the innkeeper wants to keep his patrons in their rooms, but he doesn't care to keep intruders out.","");
break;